{{- $providerClusterConfiguration := .Values.cloudProviderVsphere.internal.providerClusterConfiguration | required "internal.providerClusterConfiguration is required" }}
{{- $providerDiscoveryData := .Values.cloudProviderVsphere.internal.providerDiscoveryData | default dict }}
{{- $masterNodeGroup := $providerClusterConfiguration.masterNodeGroup | default dict }}
---
apiVersion: v1
kind: Secret
metadata:
  name: d8-node-manager-cloud-provider
  namespace: kube-system
  {{- include "helm_lib_module_labels" (list .) | nindent 2 }}
type: Opaque
data:
  type: {{ b64enc "vsphere" | quote }}
  region: {{ $providerClusterConfiguration.region | b64enc | quote }}
  zones: {{ $providerClusterConfiguration.zones | toJson | b64enc | quote }}
  instanceClassKind: {{ b64enc "VsphereInstanceClass" | quote }}
  machineClassKind: {{ b64enc "VsphereMachineClass" | quote }}

  {{- $vsphereValues := dict }}
  {{- $_ := set $vsphereValues "server" $providerClusterConfiguration.provider.server }}
  {{- $_ := set $vsphereValues "username" $providerClusterConfiguration.provider.username }}
  {{- $_ := set $vsphereValues "password" $providerClusterConfiguration.provider.password  }}
  {{- $_ := set $vsphereValues "insecure" $providerClusterConfiguration.provider.insecure }}
  {{- $_ := set $vsphereValues "regionTagCategory" $providerClusterConfiguration.regionTagCategory }}
  {{- $_ := set $vsphereValues "zoneTagCategory" $providerClusterConfiguration.zoneTagCategory }}
  {{- $_ := set $vsphereValues "region" $providerClusterConfiguration.region }}
  {{- $_ := set $vsphereValues "sshKey" $providerClusterConfiguration.sshPublicKey }}
  {{- $_ := set $vsphereValues "vmFolderPath" $providerClusterConfiguration.vmFolderPath }}

  {{- $_ := set $vsphereValues "instanceClassDefaults" dict }}
  {{- if hasKey $providerDiscoveryData "resourcePoolPath" }}
    {{- $_ := set $vsphereValues.instanceClassDefaults "resourcePoolPath" $providerDiscoveryData.resourcePoolPath }}
  {{- end }}
  {{- if hasKey $providerClusterConfiguration "disableTimesync" }}
    {{- $_ := set $vsphereValues.instanceClassDefaults "disableTimesync" $providerClusterConfiguration.disableTimesync }}
  {{- else }}
    {{- $_ := set $vsphereValues.instanceClassDefaults "disableTimesync" true }}
  {{- end }}
  {{- if $masterNodeGroup.instanceClass }}
    {{- $_ := set $vsphereValues.instanceClassDefaults "template" $masterNodeGroup.instanceClass.template }}
    {{- $_ := set $vsphereValues.instanceClassDefaults "datastore" $masterNodeGroup.instanceClass.datastore }}
  {{- end }}

  vsphere: {{ $vsphereValues | toJson | b64enc | quote }}
